package top.yueyazhui.vhr.controller.Sys.SysHr;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yueyazhui.vhr.bean.Response;
import top.yueyazhui.vhr.model.Hr;
import top.yueyazhui.vhr.model.Role;
import top.yueyazhui.vhr.service.HrService;
import top.yueyazhui.vhr.service.RoleService;
import top.yueyazhui.vhr.service.HrRoleService;

import java.util.List;

@RestController
@RequestMapping("/Sys/SysHr/Hr")
@Api(tags = "HR")
public class HrController {

    @Autowired
    HrService hrService;
    @Autowired
    RoleService roleService;
    @Autowired
    HrRoleService hrRoleService;

    @GetMapping("/")
    @ApiOperation(value = "查询所有HR", notes = "查询所有HR")
    public List<Hr> getAll(String keyword) {
        return hrService.getAll(keyword);
    }

    @PutMapping("/")
    @ApiOperation(value = "编辑HR", notes = "编辑HR")
    public Response update(@RequestBody Hr hr) {
        if(hrService.update(hr) == 1) {
            return Response.success("更新成功！");
        }
        return Response.error("更新失败！");
    }

    @GetMapping("/role")
    @ApiOperation(value = "查询所有角色", notes = "查询所有角色")
    public List<Role> getAllRole() {
        return roleService.getAll();
    }

    @PutMapping("/hr_role")
    @ApiOperation(value = "编辑HR角色", notes = "编辑HR角色")
    public Response updateHrRole(Integer hrId, Integer[] rids) {
        if(hrRoleService.update(hrId,rids)) {
            return Response.success("更新成功！");
        }
        return Response.error("更新失败！");
    }

    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Integer id) {
        if(hrService.delete(id) == 1) {
            return Response.success("删除成功！");
        }
        return Response.error("删除失败！");
    }
}
